﻿@model ScrumTracker.Models.HourLog
@{
    HtmlHelper.ClientValidationEnabled = true;
    HtmlHelper.UnobtrusiveJavaScriptEnabled = true;
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $('#CreatedAt', '#hourLogForm').datepicker();
        $('#hourLogForm').submit(function (e) {
            e.preventDefault();
            if (!$(this).valid()) {
                return;
            }
            var arr = $(this).serializeArray();
            var reqData = {};
            $(arr).each(function (i, prop) {
                reqData[prop.name] = prop.value;
            });

            var form = $(this);
            $.ajax({
                url: '@(Url.Action("create", "hourlogs"))',
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(reqData),
                contentType: 'application/json; charset=utf-8',
                success: function (data) {
                    if (!data || data.success == false) {
                        alert('error adding hour log');
                    }
                    else {
                        $('#hourLogsCnt').html(data.html);
                    }
                    $(form)[0].reset();
                }
            });
        });
    });
</script>
@using(Html.BeginForm("create", "hourlogs", FormMethod.Post, new { @id = "hourLogForm" })){
@Html.EditorForModel()
<input type="submit" value="Submit" class="button" />
} 